package com.gaohe.post.controller;

import java.util.List;
import java.io.IOException;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gaohe.common.log.annotation.Log;
import com.gaohe.common.log.enums.BusinessType;
import com.gaohe.common.security.annotation.RequiresPermissions;
import com.gaohe.post.domain.FmPostCategorize;
import com.gaohe.post.service.IFmPostCategorizeService;
import com.gaohe.common.core.web.controller.BaseController;
import com.gaohe.common.core.web.domain.AjaxResult;
import com.gaohe.common.core.utils.poi.ExcelUtil;
import com.gaohe.common.core.web.page.TableDataInfo;

/**
 * 帖子分类Controller
 * 
 * @author ruoyi
 * @date 2025-06-03
 */
@RestController
@RequestMapping("/categorize")
public class FmPostCategorizeController extends BaseController
{
    @Autowired
    private IFmPostCategorizeService fmPostCategorizeService;

    /**
     * 查询帖子分类列表
     */
    @RequiresPermissions("post:categorize:list")
    @GetMapping("/list")
    public TableDataInfo list(FmPostCategorize fmPostCategorize)
    {
        startPage();
        List<FmPostCategorize> list = fmPostCategorizeService.selectFmPostCategorizeList(fmPostCategorize);
        return getDataTable(list);
    }

    /**
     * 导出帖子分类列表
     */
    @RequiresPermissions("post:categorize:export")
    @Log(title = "帖子分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FmPostCategorize fmPostCategorize)
    {
        List<FmPostCategorize> list = fmPostCategorizeService.selectFmPostCategorizeList(fmPostCategorize);
        ExcelUtil<FmPostCategorize> util = new ExcelUtil<FmPostCategorize>(FmPostCategorize.class);
        util.exportExcel(response, list, "帖子分类数据");
    }

    /**
     * 获取帖子分类详细信息
     */
    @RequiresPermissions("post:categorize:query")
    @GetMapping(value = "/{postCategorizeId}")
    public AjaxResult getInfo(@PathVariable("postCategorizeId") Long postCategorizeId)
    {
        return success(fmPostCategorizeService.selectFmPostCategorizeByPostCategorizeId(postCategorizeId));
    }

    /**
     * 新增帖子分类
     */
    @RequiresPermissions("post:categorize:add")
    @Log(title = "帖子分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FmPostCategorize fmPostCategorize)
    {
        return toAjax(fmPostCategorizeService.insertFmPostCategorize(fmPostCategorize));
    }

    /**
     * 修改帖子分类
     */
    @RequiresPermissions("post:categorize:edit")
    @Log(title = "帖子分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FmPostCategorize fmPostCategorize)
    {
        return toAjax(fmPostCategorizeService.updateFmPostCategorize(fmPostCategorize));
    }

    /**
     * 删除帖子分类
     */
    @RequiresPermissions("post:categorize:remove")
    @Log(title = "帖子分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{postCategorizeIds}")
    public AjaxResult remove(@PathVariable Long[] postCategorizeIds)
    {
        return toAjax(fmPostCategorizeService.deleteFmPostCategorizeByPostCategorizeIds(postCategorizeIds));
    }
}
